package com.qianya.system.face.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianya.system.face.web.patient.model.PatientBoxRelevance;
import com.qianya.system.face.web.patient.service.IPatientBoxRelevanceService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * description  每一个小时删除一个一个月前的正常服药记录
 * date         2020/05/01 下午 2:21
 *
 * @author Lhl
 */
@Component
@Slf4j
public class TimingTask {
    @Autowired
    private IPatientBoxRelevanceService boxRelevanceService;
    private static Logger logger = LoggerFactory.getLogger(TimingTask.class);
    @Scheduled(cron = "0 0 0 * * ?")
    private void removeCachTask() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        //过去一月
        c.setTime(new Date());
        c.add(Calendar.MONTH, -1);
        Date m = c.getTime();
        String mon = format.format(m);
        boxRelevanceService.remove(new QueryWrapper<PatientBoxRelevance>().eq("br_state",0).le("create_time",mon));
        logger.info("清空"+mon+"前的放药缓存成功 ");
    }
}
